local wuwo = fk.CreateSkill {
  name = "th_wuwo",
  max_turn_use_time = 1,
}

wuwo:addEffect("viewas", {
  name = "th_wuwo",
  pattern = "^nullification",
  mute_card = false,
  prompt = function(self, player, selected_cards, selected)
    if selected_cards[1] then
      local first = Fk:getCardById(selected_cards[1])
      if selected_cards[2] then
        return "#th_wuwo_trd:::" .. Fk:getCardById(selected_cards[2]):toLogString() .. ":" .. first:toLogString()
      end
      return "#th_wuwo_sec:::" .. first:getTypeString() .. ":" .. first:toLogString()
    end
    return "#th_wuwo_fst"
  end,
  card_filter = function(self, player, to_select, selected)
    if #selected < 2 then
      local card = Fk:getCardById(to_select)
      -- if selected[1] then
      --   local first = Fk:getCardById(selected[1])
      --   if not ((first.type == Card.TypeBasic or (first:isCommonTrick() and not first.multiple_targets and not first.is_passive)) and
      --   (Fk.currentResponsePattern == nil and player:canUse(first)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(first))) then return end
      --   return not (player:prohibitDiscard(card) or card.type == first.type)
      -- else
      --   return (card.type == Card.TypeBasic or (card:isCommonTrick() and not card.multiple_targets and not card.is_passive)) and
      --   (Fk.currentResponsePattern == nil and player:canUse(card)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))
      -- end
      if selected[1] then
        local first = Fk:getCardById(selected[1])
        if not ((card.type == Card.TypeBasic or (card:isCommonTrick() and not card.multiple_targets and not card.is_passive)) and
        (Fk.currentResponsePattern == nil and player:canUse(card)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))) then return end
        return card.type ~= first.type
      else
        return not player:prohibitDiscard(card)
      end
    end
  end,
  view_as = function(self, player,cards)
    if #cards < 2 then return end
    local first = Fk:getCardById(cards[2])
    if not (first.type == Card.TypeBasic or (first:isCommonTrick() and not first.multiple_targets and not first.is_passive)) then return end
    local card = Fk:cloneCard(first.name, first.suit, first.number)
    card.skillName = wuwo.name
    card.extra_data = card.extra_data or {}
    card.extra_data.th_wuwoCards = cards
    return card
  end,
  before_use = function(self, player, use)
    local card = use.card
    if card and card.extra_data and card.extra_data.th_wuwoCards then
      local cards = card.extra_data.th_wuwoCards
      local room = player.room
      player:showCards(cards[2])
      room:throwCard(cards[1], wuwo.name, player, player)
    end
  end,
  enabled_at_play = function(self, player)
    return #player:getCardIds("he") >= 2 and self:withinTimesLimit(player, Player.HistoryTurn)
  end,
  enabled_at_response = function(self, player, response)
    return not response and #player:getCardIds("he") >= 2 and self:withinTimesLimit(player, Player.HistoryTurn)
  end,
  enabled_at_nullification = Util.FalseFunc
}, { check_skill_limit = true })

Fk:loadTranslationTable{
  ["th_wuwo"] = "无我",
  [":th_wuwo"] = "每回合限一次，你可以弃置一张牌并展示一张不同类型的基本牌或单目标普通锦囊牌，视为使用之。",

  ["#th_wuwo_trd"] = "无我：弃置%arg2，展示并视为使用%arg",
  ["#th_wuwo_sec"] = "无我：弃置%arg2，展示一张非%arg并视为使用之",
  ["#th_wuwo_fst"] = "无我：弃置一张牌并展示一张不同类型的基本牌或单目标普通锦囊牌，视为使用展示牌",
}

return wuwo